#coding:utf8
'''
Created on 2017/2/23
4:04
@author: Moon
qq : 550302989
'''

import datetime
import Feature

class TaskAssessManage(object):

    def __init__(self):
        # 用反射获取类方法
        # self.__Feature = __import__("Feature")
        # self.__feature = getattr(self.__Feature,"Feature")()
        self.__feature = Feature.Feature()

    # 根据任务id 查找此任务最新评价楼层数
    def findTaskAssessFloor(self,taskid):
        sql = "select max(floor) from taskassess where taskid='{taskid}'".format(taskid=taskid)
        return self.__feature.findFeatureOne(sql)

    # 添加评价（管理员权限）
    def addAssess(self,assess_info):
        sql = "inset into taskassess(taskid,assessmanid,floor,score,content,taskassess.time) values（'{taskid}','{assessmanid}','{floor}','{score}','{content}','{time}'）".format(
            taskid=assess_info['taskid'],assessmanid=assess_info['taskid'],floot=assess_info['floot'],score=assess_info['score'],content=assess_info['content'],time=datetime.datetime.now().strftime('%Y-%m-%d')
        )
        return self.__feature.dataCommitFeature(sql)

    # 查看评价（管理员权限）
    def findAssess(self,taskid):
        sql = "select taskassess.id,users.name,floor,score,content,taskassess.time from taskassess,users where users.id=taskassess.assessmanid taskid='{taskid}'".format(
            taskid=taskid
        )
        return self.__feature.findFeatureAll(sql)

    # 删除评价（至高权限）
    def deleteAssess(self,assessid):
        sql = "delete from taskassess where id='{assessid}'".format(assessid=assessid)
        return self.__feature.dataCommitFeature(sql)

